package servlet;
import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.JspWriter;

import Model.Year;
/**
 * Servlet implementation class RoleTable
 */
@WebServlet("/YearDropDown")
public class YearDropDown extends HttpServlet {
	private static final long serialVersionUID = 1L;
    JspWriter out;   
    /**
     * @see HttpServlet#HttpServlet()
     */
    public YearDropDown() {
        super();
        // TODO Auto-generated constructor stub
    }
	
    
    public YearDropDown(JspWriter outputStream) {
		// TODO Auto-generated constructor stub
		out = outputStream;
	}
    
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		javax.servlet.http.HttpSession session = request.getSession();
		if (session!=null && session.getAttribute("username")!=null)
		{
			String currentUser = session.getAttribute("username").toString();
			
			ArrayList<Year> yearTable = new ArrayList<Year>();
			yearTable = Database.YearDB.getAllYears();
			
			for(int i = 0; i < yearTable.size(); i++)
			{
	
				out.print("<option value='" + yearTable.get(i).getYearsub() + "'>");
					out.print(yearTable.get(i).getYear());
				out.print("</option>");
	
			}
		} else
			request.getRequestDispatcher("/QMS/welcome.jsp").forward(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}